﻿using Microsoft.Extensions.DependencyInjection;
using MyCommon;
using MyCommon.Caches;
using MyExtension.Redis;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyExtension.ServiceExtensions
{
    public static class CacheSetup
    {
        public static void AddCacheSetup(this IServiceCollection services)
        {
            services.AddSingleton<IConnectionMultiplexer>(sp =>
            {
                var conn = ConfigurationOptions.Parse("", true);
                conn.ResolveDns = true;
                return ConnectionMultiplexer.Connect(conn);
            });

            services.AddSingleton<IConnectionMultiplexer>(p => p.GetService<IConnectionMultiplexer>() as ConnectionMultiplexer);
            //services.AddStackExchangeRedisCache(options =>
            //{
            //    options.ConnectionMultiplexerFactory =()=>Task.FromResult(App.GetService<IConnectionMultiplexer>(false));

            //});
            services.AddTransient<IRedisBasketRepository, RedisBasketRepository>();
            services.AddSingleton<ICaching, Caching>();

        }
    }
}
